class AddIndexes < ActiveRecord::Migration
  def self.up
    # articles
    add_index :articles, :title
    add_index :articles, :user_id
    add_index :articles, :deleted_flag
    add_index :articles, :permissions
    add_index :articles, :comment_permissions
    add_index :articles, :created_at
    add_index :articles, :updated_at

    # blog_attachments
    add_index :blog_attachments, :article_id

    # board_message_attachments
    add_index :board_message_attachments, :board_message_id

    # board_messages
    add_index :board_messages, :subject, :length => 40
    add_index :board_messages, :body, :length => 100
    add_index :board_messages, :from_user_id
    add_index :board_messages, :reply_to_id
    add_index :board_messages, :board_id
    add_index :board_messages, :created_at
    add_index :board_messages, :updated_at

    # boards
    add_index :boards, :title
    add_index :boards, :description, :length => 100
    add_index :boards, :community_id
    add_index :boards, :owner_user_id

    # comments
    add_index :comments, :name
    add_index :comments, :body, :length => 100
    add_index :comments, :article_id
    add_index :comments, :user_id
    add_index :comments, :created_at
    add_index :comments, :updated_at

    # communities
    add_index :communities, :name
    add_index :communities, :description, :length => 100
    add_index :communities, :permissions
    add_index :communities, :create_board_permission
    add_index :communities, :created_at
    add_index :communities, :updated_at

    # community_member_requests
    add_index :community_member_requests, :name
    add_index :community_member_requests, :user_id
    add_index :community_member_requests, :community_id
    add_index :community_member_requests, :role_id
    add_index :community_member_requests, :target_user_id

    # community_users
    add_index :community_users, :user_id
    add_index :community_users, :community_id
    add_index :community_users, :role_id

    # events
    add_index :events, :name
    add_index :events, :start_at
    add_index :events, :end_at
    add_index :events, :created_at
    add_index :events, :updated_at

    # friend_requests
    add_index :friend_requests, :secret_code
    add_index :friend_requests, :from_user_id
    add_index :friend_requests, :to_user_id

    # friends
    add_index :friends, :friend_from_id
    add_index :friends, :friend_to_id
    add_index :friends, :created_at
    add_index :friends, :updated_at

    # invites
    add_index :invites, :inviter_name
    add_index :invites, :inviter_email
    add_index :invites, :target_email
    add_index :invites, :target_name
    add_index :invites, :user_id
    add_index :invites, :secret_code
    add_index :invites, :status
    add_index :invites, :target_user_id
    add_index :invites, :created_at
    add_index :invites, :updated_at

    # message_attachments
    add_index :message_attachments, :message_id

    # message_folders
    add_index :message_folders, :name
    add_index :message_folders, :user_id

    # message_folders_messages
    add_index :message_folders_messages, :message_folder_id
    add_index :message_folders_messages, :message_id

    # message_recipients
    add_index :message_recipients, :user_id
    add_index :message_recipients, :message_id
    add_index :message_recipients, :recipient_type
    add_index :message_recipients, :read_flag
    add_index :message_recipients, :delete_flag
    add_index :message_recipients, :created_at
    add_index :message_recipients, :updated_at

    # message_rules
    add_index :message_rules, :user_id
    add_index :message_rules, :target_column
    add_index :message_rules, :rule_type
    add_index :message_rules, :rule_value
    add_index :message_rules, :message_folder_id

    # messages
    add_index :messages, :subject, :length => 40
    add_index :messages, :body, :length => 100
    add_index :messages, :from_user_id
    add_index :messages, :reply_to_id
    add_index :messages, :created_at
    add_index :messages, :updated_at
    add_index :messages, :format_type

    # profiles
    add_index :profiles, :user_id
    add_index :profiles, :permissions

    # roles
    add_index :roles, :name

    # roles_users
    add_index :roles_users, :role_id
    add_index :roles_users, :user_id

    # settings
    add_index :settings, :user_id

    # tags
    add_index :tags, :name

    # users
    add_index :users, :login
    add_index :users, :created_at
    add_index :users, :updated_at
  end

  def self.down
    # articles
    remove_index :articles, :title
    remove_index :articles, :user_id
    remove_index :articles, :deleted_flag
    remove_index :articles, :permissions
    remove_index :articles, :comment_permissions
    remove_index :articles, :created_at
    remove_index :articles, :updated_at

    # blog_attachments
    remove_index :blog_attachments, :article_id

    # board_message_attachments
    remove_index :board_message_attachments, :board_message_id

    # board_messages
    remove_index :board_messages, :subject
    remove_index :board_messages, :body
    remove_index :board_messages, :from_user_id
    remove_index :board_messages, :reply_to_id
    remove_index :board_messages, :board_id
    remove_index :board_messages, :created_at
    remove_index :board_messages, :updated_at

    # boards
    remove_index :boards, :title
    remove_index :boards, :description
    remove_index :boards, :community_id
    remove_index :boards, :owner_user_id

    # comments
    remove_index :comments, :name
    remove_index :comments, :body
    remove_index :comments, :article_id
    remove_index :comments, :user_id
    remove_index :comments, :created_at
    remove_index :comments, :updated_at

    # communities
    remove_index :communities, :name
    remove_index :communities, :description
    remove_index :communities, :permissions
    remove_index :communities, :create_board_permission
    remove_index :communities, :created_at
    remove_index :communities, :updated_at

    # community_member_requests
    remove_index :community_member_requests, :name
    remove_index :community_member_requests, :user_id
    remove_index :community_member_requests, :community_id
    remove_index :community_member_requests, :role_id
    remove_index :community_member_requests, :target_user_id

    # community_users
    remove_index :community_users, :user_id
    remove_index :community_users, :community_id
    remove_index :community_users, :role_id

    # events
    remove_index :events, :name
    remove_index :events, :start_at
    remove_index :events, :end_at
    remove_index :events, :created_at
    remove_index :events, :updated_at

    # friend_requests
    remove_index :friend_requests, :secret_code
    remove_index :friend_requests, :from_user_id
    remove_index :friend_requests, :to_user_id

    # friends
    remove_index :friends, :friend_from_id
    remove_index :friends, :friend_to_id
    remove_index :friends, :created_at
    remove_index :friends, :updated_at

    # invites
    remove_index :invites, :inviter_name
    remove_index :invites, :inviter_email
    remove_index :invites, :target_email
    remove_index :invites, :target_name
    remove_index :invites, :user_id
    remove_index :invites, :secret_code
    remove_index :invites, :status
    remove_index :invites, :target_user_id
    remove_index :invites, :created_at
    remove_index :invites, :updated_at

    # message_attachments
    remove_index :message_attachments, :message_id

    # message_folders
    remove_index :message_folders, :name
    remove_index :message_folders, :user_id

    # message_folders_messages
    remove_index :message_folders_messages, :message_folder_id
    remove_index :message_folders_messages, :message_id

    # message_recipients
    remove_index :message_recipients, :user_id
    remove_index :message_recipients, :message_id
    remove_index :message_recipients, :recipient_type
    remove_index :message_recipients, :read_flag
    remove_index :message_recipients, :delete_flag
    remove_index :message_recipients, :created_at
    remove_index :message_recipients, :updated_at

    # message_rules
    remove_index :message_rules, :user_id
    remove_index :message_rules, :target_column
    remove_index :message_rules, :rule_type
    remove_index :message_rules, :rule_value
    remove_index :message_rules, :message_folder_id

    # messages
    remove_index :messages, :subject
    remove_index :messages, :body
    remove_index :messages, :from_user_id
    remove_index :messages, :reply_to_id
    remove_index :messages, :created_at
    remove_index :messages, :updated_at
    remove_index :messages, :format_type

    # profiles
    remove_index :profiles, :user_id
    remove_index :profiles, :permissions

    # roles
    remove_index :roles, :name

    # roles_users
    remove_index :roles_users, :role_id
    remove_index :roles_users, :user_id

    # settings
    remove_index :settings, :user_id

    # tags
    remove_index :tags, :name

    # users
    remove_index :users, :login
    remove_index :users, :created_at
    remove_index :users, :updated_at
  end
end
